package org.jl.spring.aop.controller;

import jakarta.annotation.Resource;
import org.jl.spring.aop.entity.Property;
import org.jl.spring.aop.service.AopService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

@RestController
public class AopController {

    @Resource
    private AopService aopService;

    /*
    org.jl.spring.aop.service.AopService.hello(),from A to B
    Params ===》 ["xiaoli"]
    Returns ===》 "xiaoli"
     */
    @GetMapping("hello")
    public String test(String name) {
        return aopService.hello(name);
    }

    /*
    org.jl.spring.aop.service.AopService.prop()
    Params ===》 [{"a":"haha","b":"hehe"}]
    Returns ===》 "ok"
     */
    @GetMapping("prop")
    public String prop() {
        Property prop = Property.builder().a("haha").b("hehe").build();
        aopService.prop2();
        return aopService.prop(prop);
    }

    /*
    Returns ===》 ["1","2","3","4","5"] 方法返回值
    Returns ===》 ["1","2","3","4","5"] 使用缓存值
    Returns ===》 ["1","2","3","4","5"] 方法返回值
     */
    @GetMapping("cache")
    public String cache() {
        return String.join(",", aopService.cache(Arrays.asList("1", "2", "3", "4", "5")));
    }
}
